//
//  TowerEntity.m
//  Linear Birds
//
//  Created by How Charles on 11-10-21.
//  Copyright 2011 hust. All rights reserved.
//

#import "TowerEntity.h"


@implementation TowerEntity


-(id) initWithTowerImage
{
	/////////////////////////////////////////////煽动翅膀的鸟
	NSString *fish_name=[NSString stringWithFormat:@"bird_pebbles"];
    
    
    //NSString *fish_name=[NSString stringWithFormat:@"bird_pebbles"];
    
    NSString * fish_name_plist=nil;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        fish_name_plist=@"gameEngineSpriteSheetDefault-hd.plist";
    }
    else{
        fish_name_plist=@"gameEngineSpriteSheetDefault.plist";
    }
    
	//NSString * fish_name_plist=[NSString stringWithFormat:@"gameEngineSpriteSheetDefault.plist"];
	
	// Load the Texture Atlas sprite frames, this also loads the Texture with the same name.
	CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
	[frameCache addSpriteFramesWithFile:fish_name_plist];
	
	// Loading the Ship's sprite using a sprite frame name (eg the filename)
	if ((self = [super initWithSpriteFrameName:@"spike.png"]))
	{
		/*
		 // create an animation object from all the sprite animation frames
		 CCAnimation* anim = [CCAnimation animationWithFrame:@"ship-anim" frameCount:5 delay:0.08f];
		 
		 // add the animation to the sprite (optional)
		 //[sprite addAnimation:anim];
		 
		 // run the animation by using the CCAnimate action
		 CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
		 CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];
		 [self runAction:repeat];
		 */
		
		//[self birdPowerAnimation];
		
		
	}
	return self;
}


-(id)getActions
{
	
	// Determine where to spawn the target along the Y axis
	CGSize winSize = [[CCDirector sharedDirector] winSize];
	
	int minY = self.contentSize.height/2;
	int maxY = winSize.height - self.contentSize.height/2;
	int rangeY = maxY - minY;
	int actualY = (arc4random() % rangeY) + minY;
	
	// Create the target slightly off-screen along the right edge,
	// and along a random position along the Y axis as calculated above
	self.position = ccp(winSize.width + (self.contentSize.width/2), actualY);
	
	// Determine speed of the target
	int minDuration = 2.0;
	int maxDuration = 4.0;
	int rangeDuration = maxDuration - minDuration;
	int actualDuration = (arc4random() % rangeDuration) + minDuration;
	
	// Create the actions
	id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-self.contentSize.width/2, actualY)];
	id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
	id seq=[CCSequence actions:actionMove, actionMoveDone, nil];
	
	return seq;
}


-(void)runMoveActions
{
	if (self != nil) {
		id action=[self getActions];
		[self runAction:action];
	}
	
}

@end
